package com.hontech.bv.conn.api

import com.hontech.bv.conn.Proto
import com.hontech.bv.conn.SerialPortMod
import com.hontech.bv.conn.serial.Uint16
import com.hontech.bv.conn.serial.Uint8

object PipeLine {

    /**
     * 1 落杯器1落杯
     * 2 落杯器2落杯
     * 3 落杯器1落杯并检测
     * 4 落杯器2落杯并检测
     */
    suspend fun dropCup(type: Int) {
        SerialPortMod.request(
            Proto.REQ_MASTER_DROP_CUP,
            Proto.ID_MASTER,
            arrayOf(Uint8(type))
        ).assert("落杯")
    }

    suspend fun pipeLineCtrl(position: Int) {
        SerialPortMod.request(
            Proto.REQ_MASTER_PIPELINE,
            Proto.ID_MASTER,
            arrayOf(Uint16(position))
        ).assert("流水线电机控制")
    }

    suspend fun pick(
        cup: Int,
        pearl: Int,
        powder: Int,
        ml: Int,
        steam: Int,
        ice: Int,
        stir: Int,
        temp: Int
    ) {
        SerialPortMod.request(
            Proto.REQ_PIPE_LINE_PICK,
            Proto.ID_MASTER,
            arrayOf(
                Uint8(cup),
                Uint8(pearl),
                Uint8(powder),
                Uint8(ml),
                Uint8(steam),
                Uint8(ice),
                Uint8(stir),
                Uint8(temp)
            )
        ).assert("出货")
    }

    suspend fun ledCtrl(id: Int, value: Int) {
        SerialPortMod.request(
            Proto.REQ_PIPE_LINE_LED,
            Proto.ID_MASTER,
            arrayOf(Uint8(id), Uint8(value))
        ).assert("LED控制")
    }

    suspend fun eLockOpen() {
        SerialPortMod.request(
            Proto.REQ_PIPE_LINE_ELOCK,
            Proto.ID_MASTER,
            arrayOf()
        ).assert("门锁打开")
    }
}